package com.easy.hutool;

import cn.hutool.core.convert.Convert;
import cn.hutool.core.lang.TypeReference;
import cn.hutool.core.util.CharsetUtil;

import java.util.Date;
import java.util.List;

/**
 * @author wxk
 * @Description: TODO 类型转换测试
 * @date 2021/7/6
 */
public class TypeTest {


    public static void main(String[] args) {

        /*转换为字符串：*/
        int a = 1;
        //aStr为"1"
        String aStr = Convert.toStr(a);
        long[] b = {1, 2, 3, 4, 5};
        //bStr为："[1, 2, 3, 4, 5]"
        String bStr = Convert.toStr(b);
        System.out.println("aStr:" + aStr);
        System.out.println("bStr:" + bStr);

        /*转换为指定类型数组：*/
        String[] b1 = {"1", "2", "3", "4"};
        //结果为Integer数组
        Integer[] intArray = Convert.toIntArray(b1);
        long[] c = {1, 2, 3, 4, 5};
        //结果为Integer数组
        Integer[] intArray2 = Convert.toIntArray(c);
        System.out.println("intArray数组类型:" + intArray);
        System.out.println("intArray2数组类型:" + intArray2);

        /*转换为日期对象：*/
        String a1 = "2021-06-07";
        Date value = Convert.toDate(a1);
        System.out.println("value:" + value);

        /*转换为集合*/
        Object[] a2 = {"a", "你", "好", "rr", 1};
        List<?> list = Convert.convert(List.class, a2);
        //从4.1.11开始可以这么用
        List<?> list2 = Convert.toList(a2);
        System.out.println("list:" + list);
        System.out.println("list2:" + list2);

        /*转为16进制（Hex）字符串*/
        String a16 = "我是一个小小的可爱的字符串";
        String hex = Convert.toHex(a16, CharsetUtil.CHARSET_UTF_8);
        String raw = Convert.hexToStr(hex, CharsetUtil.CHARSET_UTF_8);
        System.out.println("转为16进制hex:" + hex);
        System.out.println("16进制转为普通字符串raw:" + raw);

        /*Unicode和字符串转换*/
        String unicode = Convert.strToUnicode(a16);
        String rawUni = Convert.unicodeToStr(unicode);
        System.out.println("Unicode转为16进制unicode:" + unicode);
        System.out.println("Unicode16进制转为普通字符串rawUni:" + rawUni);

        /*金额大小写转换*/
        double money = 67556.321;
        String digitUppercase = Convert.digitToChinese(money);
        System.out.println("金额大小写转换:" + digitUppercase);
    }
}
